/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.mto.module.karaoke.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import com.mto.module.karaoke.model.Song;
import com.mto.module.karaoke.model.SongModel;
import com.mto.module.karaoke.model.SongSoap;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * The base model implementation for the Song service. Represents a row in the &quot;karaoke_Song&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.mto.module.karaoke.model.SongModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link SongImpl}.
 * </p>
 *
 * @author vuonglm
 * @see SongImpl
 * @see com.mto.module.karaoke.model.Song
 * @see com.mto.module.karaoke.model.SongModel
 * @generated
 */
@JSON(strict = true)
public class SongModelImpl extends BaseModelImpl<Song> implements SongModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a song model instance should use the {@link com.mto.module.karaoke.model.Song} interface instead.
	 */
	public static final String TABLE_NAME = "karaoke_Song";
	public static final Object[][] TABLE_COLUMNS = {
			{ "songId", Types.BIGINT },
			{ "songName", Types.VARCHAR },
			{ "songAuthor", Types.VARCHAR },
			{ "songCategory", Types.INTEGER },
			{ "songSinger", Types.VARCHAR },
			{ "recordNumber", Types.BIGINT },
			{ "songUrl", Types.VARCHAR },
			{ "createDate", Types.TIMESTAMP },
			{ "modifiedDate", Types.TIMESTAMP },
			{ "audioUrl", Types.VARCHAR }
		};
	public static final String TABLE_SQL_CREATE = "create table karaoke_Song (songId LONG not null primary key,songName VARCHAR(75) null,songAuthor VARCHAR(75) null,songCategory INTEGER,songSinger VARCHAR(75) null,recordNumber LONG,songUrl STRING null,createDate DATE null,modifiedDate DATE null,audioUrl STRING null)";
	public static final String TABLE_SQL_DROP = "drop table karaoke_Song";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.mto.module.karaoke.model.Song"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.mto.module.karaoke.model.Song"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.com.mto.module.karaoke.model.Song"),
			true);
	public static long RECORDNUMBER_COLUMN_BITMASK = 1L;
	public static long SONGAUTHOR_COLUMN_BITMASK = 2L;
	public static long SONGCATEGORY_COLUMN_BITMASK = 4L;
	public static long SONGNAME_COLUMN_BITMASK = 8L;
	public static long SONGSINGER_COLUMN_BITMASK = 16L;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static Song toModel(SongSoap soapModel) {
		if (soapModel == null) {
			return null;
		}

		Song model = new SongImpl();

		model.setSongId(soapModel.getSongId());
		model.setSongName(soapModel.getSongName());
		model.setSongAuthor(soapModel.getSongAuthor());
		model.setSongCategory(soapModel.getSongCategory());
		model.setSongSinger(soapModel.getSongSinger());
		model.setRecordNumber(soapModel.getRecordNumber());
		model.setSongUrl(soapModel.getSongUrl());
		model.setCreateDate(soapModel.getCreateDate());
		model.setModifiedDate(soapModel.getModifiedDate());
		model.setAudioUrl(soapModel.getAudioUrl());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<Song> toModels(SongSoap[] soapModels) {
		if (soapModels == null) {
			return null;
		}

		List<Song> models = new ArrayList<Song>(soapModels.length);

		for (SongSoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.mto.module.karaoke.model.Song"));

	public SongModelImpl() {
	}

	public long getPrimaryKey() {
		return _songId;
	}

	public void setPrimaryKey(long primaryKey) {
		setSongId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_songId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	public Class<?> getModelClass() {
		return Song.class;
	}

	public String getModelClassName() {
		return Song.class.getName();
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("songId", getSongId());
		attributes.put("songName", getSongName());
		attributes.put("songAuthor", getSongAuthor());
		attributes.put("songCategory", getSongCategory());
		attributes.put("songSinger", getSongSinger());
		attributes.put("recordNumber", getRecordNumber());
		attributes.put("songUrl", getSongUrl());
		attributes.put("createDate", getCreateDate());
		attributes.put("modifiedDate", getModifiedDate());
		attributes.put("audioUrl", getAudioUrl());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long songId = (Long)attributes.get("songId");

		if (songId != null) {
			setSongId(songId);
		}

		String songName = (String)attributes.get("songName");

		if (songName != null) {
			setSongName(songName);
		}

		String songAuthor = (String)attributes.get("songAuthor");

		if (songAuthor != null) {
			setSongAuthor(songAuthor);
		}

		Integer songCategory = (Integer)attributes.get("songCategory");

		if (songCategory != null) {
			setSongCategory(songCategory);
		}

		String songSinger = (String)attributes.get("songSinger");

		if (songSinger != null) {
			setSongSinger(songSinger);
		}

		Long recordNumber = (Long)attributes.get("recordNumber");

		if (recordNumber != null) {
			setRecordNumber(recordNumber);
		}

		String songUrl = (String)attributes.get("songUrl");

		if (songUrl != null) {
			setSongUrl(songUrl);
		}

		Date createDate = (Date)attributes.get("createDate");

		if (createDate != null) {
			setCreateDate(createDate);
		}

		Date modifiedDate = (Date)attributes.get("modifiedDate");

		if (modifiedDate != null) {
			setModifiedDate(modifiedDate);
		}

		String audioUrl = (String)attributes.get("audioUrl");

		if (audioUrl != null) {
			setAudioUrl(audioUrl);
		}
	}

	@JSON
	public long getSongId() {
		return _songId;
	}

	public void setSongId(long songId) {
		_songId = songId;
	}

	@JSON
	public String getSongName() {
		if (_songName == null) {
			return StringPool.BLANK;
		}
		else {
			return _songName;
		}
	}

	public void setSongName(String songName) {
		_columnBitmask |= SONGNAME_COLUMN_BITMASK;

		if (_originalSongName == null) {
			_originalSongName = _songName;
		}

		_songName = songName;
	}

	public String getOriginalSongName() {
		return GetterUtil.getString(_originalSongName);
	}

	@JSON
	public String getSongAuthor() {
		if (_songAuthor == null) {
			return StringPool.BLANK;
		}
		else {
			return _songAuthor;
		}
	}

	public void setSongAuthor(String songAuthor) {
		_columnBitmask |= SONGAUTHOR_COLUMN_BITMASK;

		if (_originalSongAuthor == null) {
			_originalSongAuthor = _songAuthor;
		}

		_songAuthor = songAuthor;
	}

	public String getOriginalSongAuthor() {
		return GetterUtil.getString(_originalSongAuthor);
	}

	@JSON
	public int getSongCategory() {
		return _songCategory;
	}

	public void setSongCategory(int songCategory) {
		_columnBitmask |= SONGCATEGORY_COLUMN_BITMASK;

		if (!_setOriginalSongCategory) {
			_setOriginalSongCategory = true;

			_originalSongCategory = _songCategory;
		}

		_songCategory = songCategory;
	}

	public int getOriginalSongCategory() {
		return _originalSongCategory;
	}

	@JSON
	public String getSongSinger() {
		if (_songSinger == null) {
			return StringPool.BLANK;
		}
		else {
			return _songSinger;
		}
	}

	public void setSongSinger(String songSinger) {
		_columnBitmask |= SONGSINGER_COLUMN_BITMASK;

		if (_originalSongSinger == null) {
			_originalSongSinger = _songSinger;
		}

		_songSinger = songSinger;
	}

	public String getOriginalSongSinger() {
		return GetterUtil.getString(_originalSongSinger);
	}

	@JSON
	public long getRecordNumber() {
		return _recordNumber;
	}

	public void setRecordNumber(long recordNumber) {
		_columnBitmask |= RECORDNUMBER_COLUMN_BITMASK;

		if (!_setOriginalRecordNumber) {
			_setOriginalRecordNumber = true;

			_originalRecordNumber = _recordNumber;
		}

		_recordNumber = recordNumber;
	}

	public long getOriginalRecordNumber() {
		return _originalRecordNumber;
	}

	@JSON
	public String getSongUrl() {
		if (_songUrl == null) {
			return StringPool.BLANK;
		}
		else {
			return _songUrl;
		}
	}

	public void setSongUrl(String songUrl) {
		_songUrl = songUrl;
	}

	@JSON
	public Date getCreateDate() {
		return _createDate;
	}

	public void setCreateDate(Date createDate) {
		_createDate = createDate;
	}

	@JSON
	public Date getModifiedDate() {
		return _modifiedDate;
	}

	public void setModifiedDate(Date modifiedDate) {
		_modifiedDate = modifiedDate;
	}

	@JSON
	public String getAudioUrl() {
		if (_audioUrl == null) {
			return StringPool.BLANK;
		}
		else {
			return _audioUrl;
		}
	}

	public void setAudioUrl(String audioUrl) {
		_audioUrl = audioUrl;
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
			Song.class.getName(), getPrimaryKey());
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		ExpandoBridge expandoBridge = getExpandoBridge();

		expandoBridge.setAttributes(serviceContext);
	}

	@Override
	public Song toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (Song)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public Object clone() {
		SongImpl songImpl = new SongImpl();

		songImpl.setSongId(getSongId());
		songImpl.setSongName(getSongName());
		songImpl.setSongAuthor(getSongAuthor());
		songImpl.setSongCategory(getSongCategory());
		songImpl.setSongSinger(getSongSinger());
		songImpl.setRecordNumber(getRecordNumber());
		songImpl.setSongUrl(getSongUrl());
		songImpl.setCreateDate(getCreateDate());
		songImpl.setModifiedDate(getModifiedDate());
		songImpl.setAudioUrl(getAudioUrl());

		songImpl.resetOriginalValues();

		return songImpl;
	}

	public int compareTo(Song song) {
		long primaryKey = song.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		Song song = null;

		try {
			song = (Song)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = song.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
		SongModelImpl songModelImpl = this;

		songModelImpl._originalSongName = songModelImpl._songName;

		songModelImpl._originalSongAuthor = songModelImpl._songAuthor;

		songModelImpl._originalSongCategory = songModelImpl._songCategory;

		songModelImpl._setOriginalSongCategory = false;

		songModelImpl._originalSongSinger = songModelImpl._songSinger;

		songModelImpl._originalRecordNumber = songModelImpl._recordNumber;

		songModelImpl._setOriginalRecordNumber = false;

		songModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<Song> toCacheModel() {
		SongCacheModel songCacheModel = new SongCacheModel();

		songCacheModel.songId = getSongId();

		songCacheModel.songName = getSongName();

		String songName = songCacheModel.songName;

		if ((songName != null) && (songName.length() == 0)) {
			songCacheModel.songName = null;
		}

		songCacheModel.songAuthor = getSongAuthor();

		String songAuthor = songCacheModel.songAuthor;

		if ((songAuthor != null) && (songAuthor.length() == 0)) {
			songCacheModel.songAuthor = null;
		}

		songCacheModel.songCategory = getSongCategory();

		songCacheModel.songSinger = getSongSinger();

		String songSinger = songCacheModel.songSinger;

		if ((songSinger != null) && (songSinger.length() == 0)) {
			songCacheModel.songSinger = null;
		}

		songCacheModel.recordNumber = getRecordNumber();

		songCacheModel.songUrl = getSongUrl();

		String songUrl = songCacheModel.songUrl;

		if ((songUrl != null) && (songUrl.length() == 0)) {
			songCacheModel.songUrl = null;
		}

		Date createDate = getCreateDate();

		if (createDate != null) {
			songCacheModel.createDate = createDate.getTime();
		}
		else {
			songCacheModel.createDate = Long.MIN_VALUE;
		}

		Date modifiedDate = getModifiedDate();

		if (modifiedDate != null) {
			songCacheModel.modifiedDate = modifiedDate.getTime();
		}
		else {
			songCacheModel.modifiedDate = Long.MIN_VALUE;
		}

		songCacheModel.audioUrl = getAudioUrl();

		String audioUrl = songCacheModel.audioUrl;

		if ((audioUrl != null) && (audioUrl.length() == 0)) {
			songCacheModel.audioUrl = null;
		}

		return songCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(21);

		sb.append("{songId=");
		sb.append(getSongId());
		sb.append(", songName=");
		sb.append(getSongName());
		sb.append(", songAuthor=");
		sb.append(getSongAuthor());
		sb.append(", songCategory=");
		sb.append(getSongCategory());
		sb.append(", songSinger=");
		sb.append(getSongSinger());
		sb.append(", recordNumber=");
		sb.append(getRecordNumber());
		sb.append(", songUrl=");
		sb.append(getSongUrl());
		sb.append(", createDate=");
		sb.append(getCreateDate());
		sb.append(", modifiedDate=");
		sb.append(getModifiedDate());
		sb.append(", audioUrl=");
		sb.append(getAudioUrl());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(34);

		sb.append("<model><model-name>");
		sb.append("com.mto.module.karaoke.model.Song");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>songId</column-name><column-value><![CDATA[");
		sb.append(getSongId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>songName</column-name><column-value><![CDATA[");
		sb.append(getSongName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>songAuthor</column-name><column-value><![CDATA[");
		sb.append(getSongAuthor());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>songCategory</column-name><column-value><![CDATA[");
		sb.append(getSongCategory());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>songSinger</column-name><column-value><![CDATA[");
		sb.append(getSongSinger());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>recordNumber</column-name><column-value><![CDATA[");
		sb.append(getRecordNumber());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>songUrl</column-name><column-value><![CDATA[");
		sb.append(getSongUrl());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>createDate</column-name><column-value><![CDATA[");
		sb.append(getCreateDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>modifiedDate</column-name><column-value><![CDATA[");
		sb.append(getModifiedDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>audioUrl</column-name><column-value><![CDATA[");
		sb.append(getAudioUrl());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = Song.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			Song.class
		};
	private long _songId;
	private String _songName;
	private String _originalSongName;
	private String _songAuthor;
	private String _originalSongAuthor;
	private int _songCategory;
	private int _originalSongCategory;
	private boolean _setOriginalSongCategory;
	private String _songSinger;
	private String _originalSongSinger;
	private long _recordNumber;
	private long _originalRecordNumber;
	private boolean _setOriginalRecordNumber;
	private String _songUrl;
	private Date _createDate;
	private Date _modifiedDate;
	private String _audioUrl;
	private long _columnBitmask;
	private Song _escapedModelProxy;
}